package com.example.taximeter.mapper;

import com.example.taximeter.bean.ParamFile;
import com.example.taximeter.bean.ParamFileView;
import org.apache.ibatis.annotations.*;


import java.util.List;

/**
 * 参数文件
 */
@Mapper
public interface ParamFileMapper {

    //查询参数文件列表
    @SelectProvider(type = ActivityMapperProvider.class, method = "findParamFileAll")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "factname", column = "fact_name"),
            @Result(property = "pricetype", column = "price_type"),
            @Result(property = "jjqtype", column = "jjq_type"),
            @Result(property = "factid", column = "fact_id"),
            @Result(property = "priceid", column = "price_id"),
            @Result(property = "jjqtypeid", column = "jjq_type_id"),
            @Result(property = "pricefileno", column = "price_file_no"),
            @Result(property = "filename", column = "file_name"),
            @Result(property = "stime", column = "s_time"),
            @Result(property = "trafficcheck", column = "traffic_check"),
            @Result(property = "pricecheck", column = "price_check"),
            @Result(property = "writeuser", column = "write_user"),
            @Result(property = "memo", column = "memo"),
            @Result(property = "metrologycheck", column = "metrology_check"),
            @Result(property = "fileid", column = "fileid")

    })
    List<ParamFileView> findParamFileAll(ParamFileView paramFileView);



    //交通部审核
    @Update("update tab_base_param_file \n" +
            "set traffic_check = 1 ,\n" +
            "traffic_time = #{traffictime,jdbcType=TIMESTAMP} \n" +
            " where id = #{id,jdbcType=VARCHAR}")
    boolean trafficCheck(ParamFile paramFile);

    //财务部审核
    @Update("update tab_base_param_file \n" +
            "set price_check = 1 ,\n" +
            "price_time = #{pricetime,jdbcType=TIMESTAMP} \n" +
            " where id = #{id,jdbcType=VARCHAR}")
    boolean priceCheck(ParamFile paramFile);

    //计量部审核
    @Update("update tab_base_param_file \n" +
            "set metrology_check = 1 ,\n" +
            "metrology_time = #{metrologytime,jdbcType=TIMESTAMP} \n" +
            " where id = #{id,jdbcType=VARCHAR}")
    boolean metrologyCheck(ParamFile paramFile);

    //添加参数文件信息
    @Insert("insert into tab_base_param_file (fact_id, price_id, jjq_type_id, \n" +
            "      price_file_no, version, fileid, id, file_name, new_bj, s_time,write_user,memo)\n" +
            "    values (#{factid,jdbcType=INTEGER}, #{priceid,jdbcType=INTEGER}, #{jjqtypeid,jdbcType=INTEGER}, \n" +
            "   #{pricefileno,jdbcType=VARCHAR}, #{version,jdbcType=VARCHAR}, #{fileid,jdbcType=VARCHAR}, \n" +
            "   #{id,jdbcType=VARCHAR}, #{filename,jdbcType=VARCHAR}, #{newbj,jdbcType=INTEGER}, \n" +
            "      #{stime,jdbcType=TIMESTAMP},#{writeuser,jdbcType=VARCHAR},#{memo,jdbcType=VARCHAR})")
    boolean addParamfile(ParamFile paramFile);

    //修改new_bj(添加时)
    @Update("update tab_base_param_file \n" +
            "set new_bj = 0 \n" +
            " where s_time < #{stime,jdbcType=TIMESTAMP} and fact_id = #{factid,jdbcType=INTEGER} and price_id = #{priceid,jdbcType=INTEGER} and jjq_type_id = #{jjqtypeid,jdbcType=INTEGER}")
    boolean updateNewbj(ParamFile paramFile);

    //修改new_bj（编辑时）
    @Update("update tab_base_param_file \n" +
            "set new_bj = 0 \n" +
            " where s_time < #{stime,jdbcType=TIMESTAMP} and fact_id = #{factid,jdbcType=INTEGER} and price_id = #{priceid,jdbcType=INTEGER} and jjq_type_id = #{jjqtypeid,jdbcType=INTEGER}")
    boolean updateNewbjEdit(ParamFileView paramFileView);

//    //查询计价器厂商列表
//    @Select("select * from tab_base_param_file  where id = #{id,jdbcType=INTEGER}")
//    @Results({
//            @Result(property = "id", column = "id"),
//            @Result(property = "factid", column = "fact_id"),
//            @Result(property = "priceid", column = "price_id"),
//            @Result(property = "jjqtypeid", column = "jjq_type_id"),
//            @Result(property = "pricefileno", column = "price_file_no"),
//            @Result(property = "filename", column = "file_name"),
//            @Result(property = "stime", column = "s_time"),
//            @Result(property = "trafficcheck", column = "traffic_check"),
//            @Result(property = "pricecheck", column = "price_check"),
//            @Result(property = "metrologycheck", column = "metrology_check")
//    })
//    ParamFile findParamFileList(@Param("id")int id);


    //修改物价文件信息
    @Update("update tab_base_param_file set fact_id = #{factid,jdbcType=INTEGER},fileid = #{fileid,jdbcType=VARCHAR},price_id = #{priceid,jdbcType=INTEGER},jjq_type_id = #{jjqtypeid,jdbcType=INTEGER},price_file_no = #{pricefileno,jdbcType=VARCHAR} ,version = #{version,jdbcType=VARCHAR}, file_name = #{filename,jdbcType=VARCHAR} , write_user = #{writeuser,jdbcType=VARCHAR} , memo = #{memo,jdbcType=VARCHAR} , s_time = #{stime,jdbcType=TIMESTAMP},new_bj = #{newbj,jdbcType=INTEGER} , traffic_check = 0 ,price_check = 0 , metrology_check = 0 where id = #{id,jdbcType=VARCHAR}")
    boolean updateParamFile(ParamFileView paramFileView);

    //删除物价文件信息
    @Delete("delete from tab_base_param_file where id = #{id,jdbcType=VARCHAR}")
    boolean deleteParamfile(String id);

    //查询参数文件列表（待审核）
    @Select("select *  from paramfile where traffic_check = 0 or price_check = 0 or metrology_check = 0 order by s_time desc")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "factname", column = "fact_name"),
            @Result(property = "pricetype", column = "price_type"),
            @Result(property = "jjqtype", column = "jjq_type"),
            @Result(property = "factid", column = "fact_id"),
            @Result(property = "priceid", column = "price_id"),
            @Result(property = "jjqtypeid", column = "jjq_type_id"),
            @Result(property = "pricefileno", column = "price_file_no"),
            @Result(property = "filename", column = "file_name"),
            @Result(property = "stime", column = "s_time"),
            @Result(property = "trafficcheck", column = "traffic_check"),
            @Result(property = "pricecheck", column = "price_check"),
            @Result(property = "metrologycheck", column = "metrology_check")
    })
    List<ParamFileView> findParamFileAllNotCheck();

    //查询参数文件列表（已审核）
    @Select("select *  from paramfile where traffic_check = 1 and price_check = 1 and metrology_check = 1 order by s_time desc")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "factname", column = "fact_name"),
            @Result(property = "pricetype", column = "price_type"),
            @Result(property = "jjqtype", column = "jjq_type"),
            @Result(property = "factid", column = "fact_id"),
            @Result(property = "priceid", column = "price_id"),
            @Result(property = "jjqtypeid", column = "jjq_type_id"),
            @Result(property = "pricefileno", column = "price_file_no"),
            @Result(property = "filename", column = "file_name"),
            @Result(property = "stime", column = "s_time"),
            @Result(property = "trafficcheck", column = "traffic_check"),
            @Result(property = "pricecheck", column = "price_check"),
            @Result(property = "metrologycheck", column = "metrology_check")
    })
    List<ParamFileView> findParamFileAllChecked();


    //查询参数文件列表
    @Select("select id , version from tab_base_param_file")
    List<ParamFileView> findParamfileList();

    //查询参数文件列表
    @Select("select id , fileid from tab_base_param_file")
    List<ParamFileView> findParamfileListFile();

    //查询参数文件列表
    @Select("select id from tab_base_param_file where price_file_no = #{pricefileno,jdbcType=VARCHAR}")
    List<ParamFile> findParamfileListByPricefileno(String pricefileno);

    //查询参数文件信息(计价器厂商id)
    @Select("select id  from tab_base_param_file where fact_id = #{factid,jdbcType=INTEGER} ")
    List<ParamFile> findParamFileByFactid(Integer factid);

    //查询参数文件信息(价格类型id)
    @Select("select id  from tab_base_param_file where price_id = #{priceid,jdbcType=INTEGER} ")
    List<ParamFile> findParamFileByPriceid(Integer priceid);

    //查询参数文件信息(计价器型号id)
    @Select("select id  from tab_base_param_file where jjq_type_id = #{jjqtypeid,jdbcType=INTEGER} ")
    List<ParamFile> findParamFileByJjqtypeid(Integer jjqtypeid);
}
